package com.baidu.springcloud.controller;

import com.baidu.springcloud.bean.Payment;
import com.baidu.springcloud.common.CommonResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author ShiLei
 * @version v1.0
 * @date 2020-04-04 16:04
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    public static HashMap<Long, Payment> hashMap = new HashMap<>();

    static {
        hashMap.put(1L, new Payment(1L, "123"));
        hashMap.put(2L, new Payment(2L, "456"));
        hashMap.put(3L, new Payment(3L, "789"));
    }

    @GetMapping("/payment/{id}")
    public CommonResult<Payment> payment(@PathVariable(value = "id") Long id) {
        Payment payment = hashMap.get(id);
        CommonResult<Payment> result = new CommonResult<>(200, "from mysql serverport :" + serverPort, payment);
        return result;
    }
}
